#include<bits/stdc++.h>
#include "base_user.h"
using namespace std;
base_user::base_user(){
    user_ID = 0;
    user_name = "小帅";
    user_dep = "信息学部";
    string password = "";

    book_id[30] = { 0 };
    debt = 0;
    book_number = 30;
    freeze_flag = 0;
}


void base_user::BorrowBook(std::string Name){//借书的功能函数
    if(freeze_flag){
        puts("该用户已被冻结!\n");
        return;
    }
    int val=script_id.get(get_hash(Name));
    script_item *item=node_sc.Find(val);
    if(item->has_brorrow==item->res_num){
        puts("暂无库存!\n");
        return;
    }
    item->has_brorrow++;
    book_id[++cnt]=val;
    cout<<"名称: "<< Name<< endl<< "出版社: "<< item->publisher<< 
        endl<<"作者: "<< item->Writer<< endl<< "版号: "<< item->ISBN<< endl;
    cout<< "库存数量: "<< item->res_num<< endl;
    time_t bro_time = time(&bro_time);
    bro.push_back({user_name,user_ID,item->name,item->id,bro_time});
    item->items_b.push_back(bro.back());
}
void base_user::ReturnBook(std::string Name){//还书的功能函数
    int val=script_id.get(get_hash(Name));
    script_item *item=node_sc.Find(val);
    item->has_brorrow--;
    time_t ret_time = time(&ret_time),bro_time;
    bool f=0;
    brorrow_item pas;
    for(auto c:bro){
        if(c.script_id==val){
            bro_time=c.bro_time;
            pas=c;
            f=1;
        }
    }
    if(!f){
        puts("未查询到借阅记录!\n");
        return;
    }
    puts("查找到的借阅记录为: ");    
    cout<<"借阅时间: "<<ctime(&pas.bro_time)<<endl;
    bool temp_is_def = (ret_time - bro_time) - restrain_bro * 24 * 3600>=0?1:0;
    if(temp_is_def){
        puts("超过规定的还书时间!\n");
        debt+=1;
    }
    if(debt==5){
        freeze_flag=true;
        puts("该用户已被冻结!\n");
    }
    ret.push_back({ user_name, user_ID , item->name,item->id ,ret_time, temp_is_def});
    item->items_r.push_back(ret.back());
}
void base_user::DisplayMesBor(){//展示全部的借还信息
    puts("展示全部的借阅信息!");
    int cnt = 0;
    for(auto c:bro){
        cout<<++cnt<<"."<<endl;
        cout<<"借书用户: "<<c.borer<<endl<<"图书: "<<c.script_name<<endl<<"借阅时间: "<<ctime(&c.bro_time)<<endl;
    }  
    puts("展示全部的还书信息: ");
    cnt=0;
    for(auto c:ret){
        cout<<++cnt<<"."<<endl;
        cout<<"借书用户: "<<c.borer<<endl<<"图书: "<<c.script_name<<endl<<"归还时间: "<<ctime(&c.acu_ret_time)<<endl;
    }
}
void base_user::ChangeDebt(){
        debt=0;
        freeze_flag=false;
        cout<<"欠款 "<<debt<<"元"<<"已缴纳完成!\n";
        return;
}//缴纳罚金